﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using _404park.Core.Crawler;

namespace _404park.Web.Models
{
    public class CrawlerResultViewModel
    {
        public IList<ProviderViewModel> Results;

        public CrawlerResultViewModel()
        {
            Results = new List<ProviderViewModel>();
        }

        public void AddProviderViewModel(ProviderViewModel providerViewModel)
        {
            Results.Add(providerViewModel);
        }
    }

    public class ProviderViewModel
    {
        public string Name { get; set; }
        public IList<FeedViewModel> Feeds { get; set; }

        public static ProviderViewModel ToViewModel(IList<Feed> feeds)
        {
            if (feeds == null || feeds.Count == 0) return null;

            return new ProviderViewModel()
            {
                Name = feeds[0].Provier.ToString(),
                Feeds = feeds.Select(x =>
                {
                    return FeedViewModel.ToViewModel(x);
                }).ToList()
            };
        }
    }

    public class FeedViewModel
    {
        public string Title { get; set; }
        public string Description { get; set; }
        public string ClickUrl { get; set; }
        public string DisplayUrl { get; set; }

        public static FeedViewModel ToViewModel(Feed feed)
        {
            if (feed == null) return null;

            return new FeedViewModel()
            {
                Title = feed.Title,
                Description = feed.Description,
                ClickUrl = feed.ClickUrl,
                DisplayUrl = feed.DisplayUrl
            };
        }
    }
}